﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WiiGeeDotNET
{
  internal class Util
  {
    internal static String BuildArrayString(double[] _array, IFormatProvider _format)
    {
      StringBuilder arrayBuilder = new StringBuilder();
      for (int i = 0; i < _array.Length; i++)
      {
        arrayBuilder.Append(_array[i].ToString(_format));
        if (i != _array.Length - 1) arrayBuilder.Append(",");
      }
      return arrayBuilder.ToString();
    }

    internal static String BuildArrayString(double[,] array, IFormatProvider _format)
    {
      StringBuilder mapBuilder = new StringBuilder();
      for (int i = 0; i < array.GetLength(0); i++)
      {
        for (int a = 0; a < array.GetLength(1); a++)
        {
          mapBuilder.Append(array[i, a].ToString(_format));
          if (a != array.GetLength(1) - 1) mapBuilder.Append(",");
        }
        if (i != array.GetLength(0) - 1) mapBuilder.Append("|");
      }
      return mapBuilder.ToString();
    }

    internal static double[,] ParseMultiDoubleArray(String _array, IFormatProvider _format)
    {

      string[] xAxisArray = _array.Split('|');
      int lengthX = xAxisArray.Length;
      int lengthY = xAxisArray[0].Split(',').Length;
      double[,] retArray = new double[lengthX, lengthY];
      for (int i = 0; i < lengthX; i++)
      {
        string[] yAxisArray = xAxisArray[i].Split(',');
        for (int a = 0; a < lengthY; a++)
        {
          retArray[i, a] = Double.Parse(yAxisArray[a], _format);
        }
      }
      return retArray;
    }

    internal static double[] ParseDoubleArray(String _array, IFormatProvider _format)
    {

      string[] xAxisArray = _array.Split(',');
      double[] retArray = new double[xAxisArray.Length];
      for (int i = 0; i < xAxisArray.Length; i++)
      {
        retArray[i] = Double.Parse(xAxisArray[i], _format);
      }
      return retArray;
    }
  }
}
